/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2019
 */

package net.dreamlu.db.manager;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import net.dreamlu.db.po.*;
import net.dreamlu.db.qo.*;
import net.dreamlu.db.repo.*;
/**
 *
 * @author lambert.wang email:lambert.wang(a)crediteyes.com
 * @version 1.0
 * @since 1.0
 */
@Service
@Transactional
public class SysLogManager {

	@Autowired
	private SysLogRepository sysLogRepository;

	public List<SysLog> queryAll() {
		return sysLogRepository.findAll();
	}

	/**
	 * 分页查询所有SysLog对象
	 * 
	 * @param pageable pageable  Pageable pageable = PageRequest.of(page, size,sort);
	 * @return
	 */
	public Page<SysLog> querySysLogByPage(Pageable pageable) {
		return sysLogRepository.findAll(pageable);
	}

	/**
	 * 根据条件分页查询SysLog对象
	 * 
	 * @param pageable
	 * @param query
	 * @return
	 */
	public Page<SysLog> querySysLogByPage(Pageable pageable, SysLogQuery sysLogQuery) {
		Specification<SysLog> example = sysLogQuery.createSpecification();
		return sysLogRepository.findAll(example, pageable);
	}

	/**
	 * 不分页查询所有SysLog对象 不分页不带排序
	 * 
	 * @param query
	 * @return
	 */
	public List<SysLog> querySysLog(SysLogQuery sysLogQuery) {
		Specification<SysLog> example = sysLogQuery.createSpecification();
		return sysLogRepository.findAll(example);
	}

	/**
	 * 不分页查询单个SysLog对象 不分页不带排序
	 * 
	 * @param query
	 * @return
	 */
	public SysLog queryUniqueSysLog(SysLogQuery sysLogQuery) {
		Specification<SysLog> example = sysLogQuery.createSpecification();
		Optional<SysLog> op = sysLogRepository.findOne(example);
		if (op.isPresent()) {
			return op.get();
		}
		return null;
	}

	/**
	 * 根据ID查询SysLog对象
	 * 
	 * @param id
	 * @return
	 */
	public SysLog querySysLogById(java.lang.Integer id) {
		Optional<SysLog> op = sysLogRepository.findById(id);
		if (op.isPresent()) {
			return op.get();
		}
		return null;
	}

	/**
	 * 保存SysLog对象
	 * 
	 * @param entity
	 */
	public void saveSysLog(SysLog sysLog) {
		sysLogRepository.save(sysLog);
	}

	/**
	 * 保存多个SysLog对象
	 * 
	 * @param entitys
	 */
	public void saveSysLog(List<SysLog> sysLogs) {
		sysLogRepository.saveAll(sysLogs);
	}

	/**
	 * 批量删除
	 * 
	 * @param deleteList
	 */
	public void deleteSysLog(List<SysLog> deleteList) {
		sysLogRepository.deleteAll(deleteList);
	}

	/**
	 * 批量删除根据查询条件
	 * 
	 * @param query
	 */
	public void deleteSysLog(SysLogQuery sysLogQuery) {
		sysLogRepository.deleteInBatch(querySysLog(sysLogQuery));
	}

	/**
	 * 批量删除根据id
	 * 
	 * @param ids
	 */
	public void deleteSysLogByIds(java.lang.Integer... ids) {
		for (java.lang.Integer id : ids) {
			sysLogRepository.deleteById(id);
		}
	}

	/**
	 * 删除单个对象
	 * 
	 * @param entity
	 */
	public void deleteSysLog(SysLog sysLog) {
		sysLogRepository.delete(sysLog);
	}
}
